package com.lenovo.manufacture.module;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.lenovo.manufacture.R;
import com.lenovo.manufacture.net.BaseActivity;

import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class module1 extends BaseActivity {
    @BindView(R.id.m1_iv)
    ImageView m1Iv;

    String isLighting;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_module1);
        ButterKnife.bind(this);
        init();
    }

    private void init() {
        dialog.show();
        json.put("id", 1);
        async(data.FactoryInfo(json), v -> {
            isLighting = v.getData().get(0).get("isLighting");
            int d = v.getData().get(0).get("isLighting").equals("0") ? R.drawable.light_close : R.drawable.light_start;
            Glide.with(this).load(d).into(m1Iv);
        });
        dialog.cancel();
    }

    @OnClick({R.id.m1_but1, R.id.m1_but2})
    public void onViewClicked(View view) {
        String s = view.getId() == R.id.m1_but1 ? "关闭" : "开启";
        String status = s.equals("关闭") ? "0" : "1";
        if (!isLighting.equals(json.get("isLighting"))) {
            json.put("isLighting", status);
            async(data.setLighting(json), v -> {
                showMsg("灯光" + s);
                init();
            });
        }

    }
}
